// mypage/accVerify/accVerify.js
var util = require("../../utils/util");

Page({
  /*页面的初始数据*/
  data: {
    mobile:'',
    mob1: '',
    show_ver: false,
    focus: true,
    time: 60,
    length:6,
    isFocus:false,
    Value:"",
    show_btn: false
  },
  /*生命周期函数--监听页面加载*/
  onLoad: function (options) {
    var that=this;
    wx.getStorage({
      key: 'userinfo',
      success:function(res){
        var userinfo=res.data;
        var mob1 = util.insertStr(util.insertStr(userinfo.phone,3," "),8," ");
        that.setData({userinfo:userinfo,mobile:userinfo.phone,mob1:mob1})
      }
    })
  },
  // 手机号
  // mobile_focus(e){
  //   var that = this;
  //   var val = e.detail.value;
  //   var mob1 = util.insertStr(util.insertStr(val,3," "),8," ");
  //   that.setData({mobile:val, mob1:mob1})
  // }, 
  mobile_tap(e){
    var that = this;
    that.setData({ mobile:e.detail.value })
  },
  send_mobile:function(){
    var that = this,mobile = that.data.mobile;
    var neg=(/^1[3456789]\d{9}$/);
    if(!neg.test(mobile)||!mobile){
      util.page_show_toast('手机号码输入有误',1500)
      return false;
    }
    that.setData({show_ver: true,isFocus: true});
    that.interval();
  },
  // 验证码
  ver_focus(e){
    var that = this;
    var inputValue = e.detail.value;
    that.setData({ Value:inputValue, })
    if(inputValue.length == 6){
     that.setData({show_page: 1,type:1})
    }
  }, 
  ver_tap(){
    var that = this;
    that.setData({ isFocus:true, })
  },
  // 倒计时
  interval:function(){
    var that = this,time=that.data.time;
    var tms=setInterval(function(){
      time--;
      that.setData({time: time})
      if(time==0){
        clearInterval(tms)
        that.setData({time: 60,show_btn: true})
      }
    },1000)
  },
  again_send:function(){
    var that = this,show_btn=that.data.show_btn;
    if(show_btn){
      //
      that.interval();
      that.setData({show_btn: false})
    }
  },
})